package myta.bean;

import javax.faces.component.html.HtmlDataTable;

import myta.base.FormBase;
import myta.model.DataRow;
import myta.model.DataTable;
import myta.service.Command;
import myta.service.SQLexec;

public class Jurusan extends FormBase{
	private HtmlDataTable htmldatatable;
	private DataTable datatable;

	@Override
	public void init() throws Exception {
		formName = "jurusan";
		
		htmldatatable = new HtmlDataTable();
		datatable = new DataTable();
	}
	
	@Override
	public void hapus() throws Exception {
		int selectedRow = htmldatatable.getRowIndex();
		DataRow datarow = datatable.getRow(selectedRow);
		String idjurusan = datarow.getString("idjurusan");
		
		String sql = "delete from jurusan where idjurusan = ?";
		Command command = SQLexec.makeCommand(sql);
		command.setObject(1, idjurusan);
		command.executeUpdate();
	}

	@Override
	public void tampil() throws Exception {
		String sql = "select * from jurusan order by idjurusan desc";
		Command command = SQLexec.makeCommand(sql);
		datatable = command.executeQuery();
	}

	public HtmlDataTable getHtmldatatable() {
		return htmldatatable;
	}

	public void setHtmldatatable(HtmlDataTable htmldatatable) {
		this.htmldatatable = htmldatatable;
	}

	public DataTable getDatatable() {
		return datatable;
	}

	public void setDatatable(DataTable datatable) {
		this.datatable = datatable;
	}
}
